package com.zsc.wxapp.controller.endUser;

import com.zsc.wxapp.context.BaseContext;
import com.zsc.wxapp.entity.dto.PriceTagDTO;
import com.zsc.wxapp.entity.dto.SubmitTaskDTO;
import com.zsc.wxapp.entity.vo.PriceTagVO;
import com.zsc.wxapp.entity.vo.ProfitAnalysisVO;
import com.zsc.wxapp.result.Result;
import com.zsc.wxapp.services.PriceTagService;
import com.zsc.wxapp.services.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("endUserPriceTagController")
@RequestMapping("/api/wxapp/endUser")
@Slf4j
//@Api(tags = "C端-价签相关接口")
public class PriceTagController {

    @Resource
    private PriceTagService priceTagService;
    @Resource
    private UserService userService;

    /**
     * 获取当前用户识别的价签数据
     * @return Result
     */
    @GetMapping("/getPriceTags")
//    @ApiOperation("获取当前用户识别的价签数据")
    public Result<List<PriceTagVO>> getPriceTagsByUserId() {
        Long userId = BaseContext.getCurrentId();
        List<PriceTagVO> result = priceTagService.getPriceTagsByUserId(userId);
        return Result.success(result);
    }

    /**
     * 终端用户盈利分析
     * @return ProfitAnalysisVO
     */
    @GetMapping("/profitAnalysis")
//    @ApiOperation("终端用户盈利分析")
    public Result<ProfitAnalysisVO> profitAnalysis() {
        Long userId = BaseContext.getCurrentId();
        ProfitAnalysisVO result = priceTagService.profitAnalysis(userId);
        if (result == null) {
            return Result.error("改用户还没上传本店价签数据");
        }
        return Result.success(result);
    }

    /**
     * 根据价签id修改价签数据 可能弃用
     * @param priceTagDTO 修改后的数据接收类
     * @return Result
     */
    @PutMapping("/updatePriceTag")
//    @ApiOperation("修改价签数据")
    public Result<?> updatePriceTag(@RequestBody PriceTagDTO priceTagDTO) {
        log.info("修改价签数据：priceTagDTO：{}", priceTagDTO);
        priceTagService.updatePriceTag(priceTagDTO);
        return Result.ok("修改成功！");
    }

    /**
     * C端用户提交任务到B端用户
     * @param submitTaskDTO
     */
    @PostMapping("/submitTask")
//    @ApiOperation("提交任务信息")
//    @ApiImplicitParam(name = "submitTaskDTO", value = "提交任务信息", required = true, dataTypeClass = SubmitTaskDTO.class)
    public Result<?> submitTask(@RequestBody SubmitTaskDTO submitTaskDTO) {
        Long userId = BaseContext.getCurrentId();
        submitTaskDTO.setSubmitUserId(userId);
        log.info("C端用户上传任务数据, submitTaskDTO:{}", submitTaskDTO);
        priceTagService.submitTask(submitTaskDTO);
        return Result.success();
    }

    /**
     * 根据商品名称查询价签
     * @param name 卷烟名称
     */
    @GetMapping("/selectPriceTagByName")
//    @ApiOperation("根据商品名称查询价签")
//    @ApiImplicitParam(name = "name", value = "商品名称", required = true, dataTypeClass = String.class)
    public Result<List<PriceTagVO>> selectPriceTagByName(String name) {
        Long userId = BaseContext.getCurrentId();
        List<PriceTagVO> result = priceTagService.searchPriceTagByName(userId, name);
        return Result.success(result);
    }

    /**
     * 批量删除价签数据
     * @param priceTagDTOs
     */
    @DeleteMapping("/deleteByIds")
//    @ApiOperation("批量删除价签数据")
    public Result<?> deleteByIds(@RequestBody List<PriceTagDTO> priceTagDTOs) {
        log.info("批量删除价签数据,priceTagDTOs:{}", priceTagDTOs);
        priceTagService.deleteByIds(priceTagDTOs);
        return Result.success();
    }

    /**
     * 添加价签数据
     * @param priceTagDTOs
     */
    @PostMapping("addPriceTags")
//    @ApiOperation("创建价格标签")
    public Result<?> addPriceTag(@RequestBody List<PriceTagDTO> priceTagDTOs) {
        priceTagService.addPriceTags(priceTagDTOs, BaseContext.getCurrentId());
        return Result.success();
    }
}
